package com.zzccyy.jpdemo.utils;


import android.content.Intent;
import android.text.TextUtils;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zzccyy.jpdemo.R;
import com.zzccyy.jpdemo.bean.SearchListBean;
import com.zzccyy.jpdemo.page.TrainInfoActivity;

import java.util.List;


public class ListAdapter1 extends BaseQuickAdapter<SearchListBean.DataBean.ListBean, BaseViewHolder> {


    public ListAdapter1(int layoutResId) {
        super(layoutResId);

    }


    @Override
    protected void convert(BaseViewHolder helper, SearchListBean.DataBean.ListBean item) {
        TextView ttTime1 = helper.getView(R.id.ttTime1);
        TextView ttTime2 = helper.getView(R.id.ttTime2);
        TextView ttAdd1 = helper.getView(R.id.ttAdd1);
        TextView ttAdd2 = helper.getView(R.id.ttAdd2);
        TextView ttNum = helper.getView(R.id.ttNum);
        TextView ttTime = helper.getView(R.id.ttTime);
        TextView ttPrice = helper.getView(R.id.ttPrice);
        RecyclerView recyclerView = helper.getView(R.id.recyclerView);

        if (!TextUtils.isEmpty(item.departuretime)){
            ttTime1.setText(item.departuretime);
        }
        if (!TextUtils.isEmpty(item.arrivaltime)){
            ttTime2.setText(item.arrivaltime);
        }
        if (!TextUtils.isEmpty(item.station)){
            ttAdd1.setText(item.station);
        }
        if (!TextUtils.isEmpty(item.endstation)){
            ttAdd2.setText(item.endstation);
        }


        if (!TextUtils.isEmpty(item.trainno)){
            ttNum.setText(item.trainno);
        }
        if (!TextUtils.isEmpty(item.costtime)){
            ttTime.setText(item.costtime);
        }
        if (!TextUtils.isEmpty(item.minPrice)){
            ttPrice.setText("￥"+ item.minPrice +"起");
        }
        GridLayoutManager linearLayoutManager = new GridLayoutManager(mContext,4);
        List<SearchListBean.DataBean.ListBean.TicketListBean> ticketList = item.ticketList;
        ListAdapter2 listAdapter2 = new ListAdapter2(mContext,ticketList,R.layout.item_search2);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(listAdapter2);
        helper.itemView.setOnClickListener(v->{
            Intent intent = new Intent(mContext, TrainInfoActivity.class);
            intent.putExtra("data",item);
            mContext.startActivity(intent);
        });

   }

}

